<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex align-center benben-position-layout flex offerPay_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex align-center self-center justify-between flex-sub offerPay_fd0_0'>
					<view class='flex flex-wrap align-center offerPay_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
						<text class='fu-iconfont2  searchRusult_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center flex-sub'>
						<text class='offerPay_fd0_0_c1_c0'>收银台</text>
					</view>
					<view class='flex flex-wrap align-center offerPay_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>

			<view class="flex flex-direction flex-wrap align-center benben-flex-layout offerPay_flex_1">
				<view class='flex flex-wrap align-end offerPay_fd1_0'>
					<text class='offerPay_fd1_0_c0'>￥</text>
					<text class=' offerPay_fd1_0_c1'>
						<text class=' offerPay_price1_fd1_0_c1'>{{ money | frontPrice }}</text>
						<text class=' offerPay_price2_fd1_0_c1'>{{ money | laterPrice }}</text>
					</text>
				</view>
				<view class='flex flex-wrap align-center offerPay_fd1_1'>
					<text class='offerPay_fd1_1_c0'>支付剩余时间：</text>
					<benben-countdown class='offerPay_fd1_1_c1' :show-day='false' :count-time="time"
						v-if="this.time<this.daojishi" @time-end="timeEnd">
						<template #default="{ d, h, i, s }">
							<text class='offerPay_fd1_1_c0'>{{h}}</text>

							<text class='offerPay_fd1_1_c0'>:</text>

							<text class='offerPay_fd1_1_c0'>{{i}}</text>

							<text class='offerPay_fd1_1_c0'>:</text>

							<text class='offerPay_fd1_1_c0'>{{s}}</text>

							<text class='offerPay_fd1_1_c0'></text>
						</template>
					</benben-countdown>
					<benben-countdown class='offerPay_fd1_1_c1' :show-day='true' :count-time="time"
						v-if="this.time>=this.daojishi" @time-end="timeEnd">
						<template #default="{ d, h, i, s }">
							<text>{{d}}</text>

							<text>天</text>

							<text class='offerPay_fd1_1_c0'>{{h}}</text>

							<text class='offerPay_fd1_1_c0'>:</text>

							<text class='offerPay_fd1_1_c0'>{{i}}</text>

							<text class='offerPay_fd1_1_c0'>:</text>

							<text class='offerPay_fd1_1_c0'>{{s}}</text>

							<text class='offerPay_fd1_1_c0'></text>
						</template>
					</benben-countdown>
				</view>
			</view>


			<!---flex布局flex布局开始-->
			<view class="flex benben-flex-layout flex-wrap align-center offerPay_flex_2">
			</view>

			<!---flex布局flex布局结束-->
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout offerPay_flex_3">
				<text class='offerPay_fd3_0'>选择支付方式</text>
				<benben-select-diy ref="showSelectPopup1687683901811"
					class-name='flex flex-direction flex-wrap align-stretch flex' :items.sync="dataType" v-model="payID"
					:label.sync="payLable" default-type="pay_type" default-label="name" :allow-cancel='false'
					type="radio" :disabled='false' v-if="dataType.length!='0'">
					<template v-for='(item,key0) in dataType'>
						<view v-if="item.isSelected" class='flex align-center flex offerPay_fd3_1_c0' :key="key0"
							@tap="$refs.showSelectPopup1687683901811.tapHandle(key0)">
							<image class='offerPay_fd3_1_c0_c0' mode="aspectFit" :src='item.image'></image>
							<text class='offerPay_fd3_1_c0_c1'>{{item.name}}</text>
							<image class='offerPay_fd3_1_c0_c2' mode="aspectFit" :src='STATIC_URL+"3.png"'></image>
						</view>
						<view v-else class='flex align-center flex offerPay_fd3_1_c0' :key="key0"
							@tap="$refs.showSelectPopup1687683901811.tapHandle(key0)">
							<image class='offerPay_fd3_1_c0_c0' mode="aspectFit" :src='item.image'></image>
							<text class='offerPay_fd3_1_c0_c1'>{{item.name}}</text>
							<image class='offerPay_fd3_1_c1_c2' mode="aspectFit" :src='STATIC_URL+"336.png"'></image>
						</view>
					</template>
				</benben-select-diy>
				<button class='offerPay_fd3_2' @tap.stop="immediatePaymentFunc()">确认支付</button>
			</view>

			
			
			<benben-popup v-model="popupShow1685686587824" :mask="true" :mask-close-able="true" mode='center'>

				<view class="flex benben-flex-layout flex-wrap align-center">
					<view class='flex flex-direction flex-wrap align-center offerPay_fd6_0'>
						<text class='offerPay_fd6_0_c0'>请输入密码</text>
						<benben-digital-password :box-num='6' mode='password'
							class-name='flex flex align-center justify-center offerPay_fd6_0_c1'
							@confirm="balancepayFunc()" v-model="pay_password" :init-open.sync="xianshi">
							<template #default="{ content, active, index }">
								<view :key="index" v-if="active"
									class="flex align-center justify-center active-digital-password offerPay_flex_password_active_fd6_0_c1">
									{{ content }}
								</view>
								<view :key="index" v-else
									class="flex align-center justify-center offerPay_flex_password_noActive_fd6_0_c1">
									{{ content }}
								</view>
							</template>
						</benben-digital-password>
						<view class='flex align-stretch offerPay_fd6_0_c2'>
							<button class='offerPay_fd6_0_c2_c0' @tap.stop="closePopupFunc()">取消</button>
							<button class='offerPay_fd6_0_c2_c1' @tap.stop="balancepayFunc()">确定</button>
						</view>
					</view>
				</view>



			</benben-popup>


		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				"popupShow1685686587824": false,
				"popupShow1679651812141": false,
				"payLable": "微信支付",
				"pay_password": "",
				"dataMessage": {},
				"payID": "wxpay",
				"dataType": [
					{
						pay_type: 'wxpay',
						name: '微信支付',
						image: '/static/images/174.png'
					},
					{
						pay_type: 'alipay',
						name: '支付宝支付',
						image: '/static/images/317.png'
					}
					// {
					// 	pay_type: 'balance',
					// 	name: '余额支付',
					// 	image: 'https://oss.tiantianhuoke.com/images/168371455948373.png'
					// }
				],
				
				"shifoupwsd": {
					"falg": ""
				},
				"xianshi": true,
				"datashifoucom": {
					"falg": ""
				},
				
				"end_time": "1800",
				"loading": false,
				"daojishi": 86400,
				"order_sn": "GD20230625191830714165",
				"money": "0",
				"time": "0",
				"order_type": "3",
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {
				order_sn,
				money,
				time,
				order_type
			} = options
			if (order_sn !== undefined) this.order_sn = order_sn
			if (money !== undefined) this.money = money
			if (time !== undefined) this.time = time
			if (order_type !== undefined) this.order_type = order_type
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			timeEnd() {
				uni.navigateBack();
			},
			//立即支付
			immediatePaymentFunc() {
				if (!validate(this.payID, 'require')) {
					this.$message.info('请选择支付方式');
					return false;
				}
				if (this.payID == 'balance') {
					// if (this.shifoupwsd.falg == 0) {
					// 	this.popupShow1687342431187 = true;
					// } else {
					// 	if (+this.dataMessage.user_money < this.money) {
					// 		this.$message.info('余额不足');
					// 		return
					// 	}
					// 	this.popupShow1685686587824 = true;
					// }
					this.balancepayFunc();
				} else if (this.payID == 'wxpay') {
					if (this.loading) return
					this.loading = true;
					this.paymentByWxpayFunc()
				} else if (this.payID == 'alipay') {
					if (this.loading) return
					this.loading = true;
					this.paymentByAlipayFunc()
				}
			},
			
			//余额支付
			async balancepayFunc() {
				// if (!validate(this.pay_password, 'require')) {
				// 	this.$message.info('请输入支付密码');
				// 	return false;
				// }
				let datadatashifoucom = await this.$api.post(global.apiUrls.post63feb2ce76ac6, {
					order_sn: this.order_sn
				});
				this.$message.info(datadatashifoucom.data.msg);
				if (datadatashifoucom.data.code != 1) {
					this.pay_password = ''
					return
				}
				let infodatashifoucom = datadatashifoucom.data;
				this.datashifoucom = infodatashifoucom.data;
				setTimeout(() => {
					this.paySuccessFunc();
				}, 800)
			},
			
			
			//关闭弹窗
			closePopupFunc() {
				this.pay_password = '';
				this.popupShow1685686587824 = false;
			},
			//支付跳转页面
			paySuccessFunc() {
				this.$urouter.redirectTo(`/pages/sy/resultPayment/resultPayment?order_sn=${this.order_sn}&payID=${this.payID}`);
			},
			//微信支付
			paymentByWxpayFunc() {
				this.$api
					.post(global.apiUrls.post62e335233b477, {
						order_sn: this.order_sn,
						// #ifdef APP-PLUS||H5
						ismini: '0',
						// #endif
						// #ifdef MP-WEIXIN
						ismini: '1'
						// #endif
					})
					.then(res => {
						console.log('微信支付回调', res);
						if (res.data.code == 1) {
							let data = res.data.data;
							console.log('支付信息', data);
							uni.requestPayment({
								provider: 'wxpay',
								// #ifdef MP-WEIXIN
								timeStamp: data.timeStamp,
								nonceStr: data.nonceStr,
								package: data.package,
								signType: data.signType,
								paySign: data.paySign,
								// #endif
								// #ifdef APP-PLUS
								orderInfo: data,
								// #endif
								success: e => {
									console.log('success', e);
									if (e.errMsg == 'requestPayment:ok') {
										this.$message.info('支付成功');
										setTimeout(() => {
											this.paySuccessFunc();
										}, 800)
									}
								},
								fail: e => {
									console.log('fail', e);
									// #ifdef APP-PLUS
									let failMsg = 'requestPayment:fail canceled';
									// #endif
									// #ifndef APP-PLUS
									let failMsg = 'requestPayment:fail cancel';
									// #endif
									if (e.errMsg == failMsg) {
										this.$message.info(this.$t('取消支付'));
									} else {
										this.$message.info(this.$t('支付失败,请稍后重试'));
										// this.$message.info("支付失败,原因为: " + e.errMsg);
									}
								},
								complete: () => {
									this.loading = false;
								}
							});
						} else {
							this.loading = false;
							this.$message.info(this.$t('订单无效，支付失败'));
						}
					})
					.catch(err => {
						this.loading = false;
						console.error('微信支付失败 =>', err);
					});
			},
			//支付宝支付
			paymentByAlipayFunc() {
				this.$api
					.post(global.apiUrls.post62e342a23919c, {
						order_sn: this.order_sn
					})
					.then(res => {
						console.log('支付宝支付回调', res);
						if (res.data.code == 1) {
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: res.data.data,
								success: e => {
									if (e.errMsg == 'requestPayment:ok') {
										this.$message.info('支付成功');
										setTimeout(() => {
											this.paySuccessFunc();
										}, 800)
									}
								},
								fail: e => {
									if (e.errMsg == 'requestPayment:fail canceled') {
										this.$message.info(this.$t('取消支付'));
									} else {
										this.$message.info(this.$t('支付失败,请稍后重试'));
									}
								},
								complete: () => {
									this.loading = false;
								}
							});
						} else {
							this.loading = false;
							this.$message.info(this.i18n['订单无效，支付失败']);
						}
					})
					.catch(err => {
						this.loading = false;
						console.log('支付宝支付失败 => ', err);
					});
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(248, 248, 248, 1);
		background-size: 100% auto;
	}

	.offerPay_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.offerPay_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.offerPay_fd0_0_c0_c0 {
		width: 36rpx;
		height: 36rpx;
	}

	.offerPay_fd0_0_c0 {
		width: 100rpx;
		height: 88rpx;
	}

	.offerPay_fd0_0 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.offerPay_flex_1 {
		background: #fff;
		background-size: 100% auto !important;
	}

	.offerPay_fd1_1_c1 {
		background: #FFFFFF;
	}

	.offerPay_fd1_1_c0 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #666666;
	}

	.offerPay_fd1_1 {
		margin: 0rpx 0rpx 56rpx 0rpx;
	}

	.offerPay_price2_fd1_0_c1 {
		font-size: 64rpx;
		color: rgba(255, 80, 80, 1);
	}

	.offerPay_price1_fd1_0_c1 {
		line-height: 36rpx;
		font-size: 64rpx;
		font-weight: 700;
		color: rgba(255, 80, 80, 1);
	}

	.offerPay_fd1_0_c1 {
		color: var(--benbenFontColor7);
		font-weight: 700;
		line-height: 94rpx;
		font-size: 64rpx;
	}

	.offerPay_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 700;
		color: rgba(255, 80, 80, 1);
		line-height: 100rpx;
		transform: translateY(10rpx);
	}

	.offerPay_fd1_0 {
		margin: 66rpx 0rpx 24rpx 0rpx;
	}

	.offerPay_flex_2 {
		background: rgba(246, 247, 249, 1);
		height: 20rpx;
		background-size: 100% auto !important;
	}

	.offerPay_flex_3 {
		background: #fff;
		background-size: 100% auto !important;
		padding: 0rpx 32rpx 12rpx 32rpx;
		margin: 0rpx 0rpx 120rpx 0rpx;
	}

	.offerPay_fd3_2 {
		background: var(--benbenbgColor0);
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 80rpx;
		line-height: 80rpx;
		position: fixed;
		bottom: calc(32rpx + var(--window-bottom));
		border-radius: 8rpx;
	}

	.offerPay_fd3_1_c1_c2 {
		width: 37rpx;
		height: 37rpx;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
		margin: 0rpx 0rpx 0rpx auto;
	}

	.offerPay_fd3_1_c0_c2 {
		width: 36rpx;
		height: 36rpx;
		border-radius: 18rpx 18rpx 18rpx 18rpx;
		margin: 0rpx 0rpx 0rpx auto;
	}

	.offerPay_fd3_1_c0_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333333;
		line-height: 45rpx;
	}

	.offerPay_fd3_1_c0_c0 {
		width: 56rpx;
		height: 56rpx;
		border-radius: 26rpx 26rpx 26rpx 26rpx;
		margin: 0rpx 24rpx 0rpx 0rpx;
	}

	.offerPay_fd3_1_c0 {
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.offerPay_fd3_0 {
		border-bottom: 1px solid #eee;
		font-size: 28rpx;
		font-weight: 400;
		color: #666666;
		padding: 32rpx 0rpx 32rpx 0rpx;
		line-height: 40rpx;
	}

	.offerPay_flex_4 {
		width: 540rpx;
	}

	.offerPay_fd4_0_c1_c1 {
		background: #fff;
		font-size: 32rpx;
		color: var(--benbenFontColor5);
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		height: 110rpx;
		line-height: 110rpx;
	}

	.offerPay_fd4_0_c1_c0 {
		border-right: 1px solid rgba(238, 238, 238, 1);
		background: #fff;
		font-size: 32rpx;
		color: var(--benbenFontColor2);
		border-radius: 0rpx 0rpx 0rpx 16rpx;
		height: 110rpx;
		line-height: 110rpx;
	}

	.offerPay_fd4_0_c0_c1_c0_c1 {
		background: #FFFFFF;
	}

	.offerPay_fd4_0_c0_c1_c0 {
		text-align: center;
	}

	.offerPay_fd4_0_c0_c0 {
		color: #333333;
		font-size: 32rpx;
		font-weight: 500;
		line-height: 45rpx;
		margin: 0rpx 0rpx 40rpx 0rpx;
	}

	.offerPay_fd4_0_c0 {
		border-bottom: 1px solid rgba(238, 238, 238, 1);
		padding: 40rpx 30rpx 32rpx 30rpx;
		border-radius: 16rpx 16rpx 0rpx 0rpx;
	}

	.offerPay_fd4_0 {
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.offerPay_flex_5 {
		background: #fff;
		width: 540rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.offerPay_fd5_1_c1 {
		border-top: 1px solid #eee;
		border-left: 1px solid #eee;
		background: #fff;
		line-height: 94rpx;
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		font-size: 32rpx;
		color: var(--benbenFontColor8);
		padding: 0rpx 100rpx 0rpx 100rpx;
		font-weight: 500;
	}

	.offerPay_fd5_1_c0 {
		border-top: 1px solid #eee;
		background: #fff;
		line-height: 94rpx;
		border-radius: 0rpx 0rpx 0rpx 16rpx;
		font-size: 32rpx;
		color: var(--benbenFontColor2);
		padding: 0rpx 102rpx 0rpx 103rpx;
		font-weight: 400;
	}

	.offerPay_fd5_0 {
		line-height: 44rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		margin: 91rpx 0rpx 88rpx 0rpx;
	}

	.offerPay_fd6_0_c2_c1 {
		background: #fff;
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		font-size: 33rpx;
		color: var(--benbenFontColor5);
		width: 269rpx;
		font-weight: 500;
		line-height: 94rpx;
	}

	.offerPay_fd6_0_c2_c0 {
		border-right: 1px solid #eee;
		background: #fff;
		border-radius: 0rpx 0rpx 0rpx 16rpx;
		font-size: 32rpx;
		color: var(--benbenFontColor2);
		line-height: 94rpx;
		width: 269rpx;
		font-weight: 400;
	}

	.offerPay_fd6_0_c2 {
		border-top: 1px solid #eee;
	}

	.offerPay_flex_password_noActive_fd6_0_c1 {
		border: 1px solid #ccc;
		width: 68rpx;
		height: 68rpx;
	}

	.offerPay_flex_password_active_fd6_0_c1 {
		border: 1px solid #409EFF;
		width: 68rpx;
		height: 68rpx;
	}

	::v-deep .offerPay_fd6_0_c1 {
		margin: 32rpx 0rpx 32rpx 0rpx;
	}

	.offerPay_fd6_0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		margin: 0rpx 0rpx 32rpx 0rpx;
	}

	.offerPay_fd6_0 {
		background: #fff;
		width: 540rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		background-size: 100% auto !important;
		padding: 40rpx 0rpx 0rpx 0rpx;
	}
	.searchRusult_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
	}
</style>